home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / misc / avmnfaxsrc1_33.lha / callback.c < prev    next >
C/C++ Source or Header  |  1994-05-25  |  1KB  |  49 lines

  1. /* $Header: pd:zvmrcs/callback.c,v 1.1 1993/04/07 18:47:36 rvillari Exp $ */
  2. #include <stdlib.h>
  3.  
  4. #include "callback_proto.h"
  5.  
  6. /* EXPORTS */
  7. struct CallBack initCallBack; /* this is just an initialization */
  8.  
  9. void deleteCallBack(struct CallBack* cb) {
  10.   cb->numCallBacks--;
  11. }
  12.  
  13. void addCallBack(struct CallBack* cb, ULONG match, enum ReturnStatus (*function)(void)) {
  14.   int count = cb->numCallBacks;
  15.   /* need some safety here */
  16.   if (count == 5) exit(20);
  17.   
  18.  
  19.   cb->signalMatch[count] = match;
  20.   cb->functionPtr[count] = function;
  21.  
  22.   cb->numCallBacks++;
  23. }
  24.  
  25. enum ReturnStatus processCallBack(struct CallBack* cb, ULONG signalsReceived) {
  26.   int i;
  27.   enum ReturnStatus status;
  28.  
  29.   for (i = 0; i < cb->numCallBacks; i++) {
  30.     if (signalsReceived & cb->signalMatch[i]) {
  31.       SetSignal(0L, cb->signalMatch[i]);
  32.       status = cb->functionPtr[i]();
  33.       if (status != Normal) return status;
  34.     }
  35.   }
  36.   return Normal;
  37. }
  38.  
  39. ULONG callBackSignals(struct CallBack* cb) {
  40.   ULONG signals = 0L;
  41.   int i;
  42.  
  43.   for (i = 0; i < cb->numCallBacks; i++)
  44.     signals |= cb->signalMatch[i];
  45.  
  46.   return signals;
  47. }
  48.  
  49.